import api from '@/api';
import type { AxiosPromise } from 'axios';

export interface RechargesListRequest {
  _action: string;
  page: number;
  audit_status?: number;
  created_at?: string[];
  perPage: number;
}

export interface RechargeRecord {
  id: string;
  amount: string;
  pay_type: string;
  audit_status: string;
  created_at: string;
  voucher?: string;
  money?: string;
  exchange_rate?: string;
  money_cny?: string;
  audit_reason?: string;
  updated_at?: string;
}

export interface RechargesListResponse {
  items: RechargeRecord[];
  total: number;
}

// 获取充值记录列表
export const getRechargesList = (params: RechargesListRequest): AxiosPromise<RechargesListResponse> => {
  return api.get('api/recharges', { params });
};

export interface FundDetailItem {
  transactionId: string;
  type: 'income' | 'expense';
  amount: number;
  paymentMethod: string;
  status: 'success' | 'pending' | 'failed';
  transactionTime: string;
  remark?: string;
}

export interface FundDetailsRequest {
  page: number;
  pageSize: number;
  transactionId?: string;
  type?: 'income' | 'expense';
  status?: 'success' | 'pending' | 'failed';
  startTime?: string;
  endTime?: string;
}

export interface FundDetailsResponse {
  list: FundDetailItem[];
  total: number;
  statistics?: {
    totalIncome: number;
    totalExpense: number;
    transactionCount: number;
  };
}

// 获取资金明细列表
export const getFundDetails = (params: FundDetailsRequest): AxiosPromise<FundDetailsResponse> => {
  return api.get('api/fund/details', { params });
};

export default {
  getRechargesList,
  getFundDetails,
};